const mongoose = require("mongoose"); //导入
mongoose.connect("mongodb://127.0.0.1:27017/test") //数据库名

const tagSchema = new mongoose.Schema({
    // text:String   // string类型  进行约束
    text:{
        type:String,
        minlength:2,
        maxlength:12
    }
})
const tagModel = new mongoose.model("tag",tagSchema); 


const contentSchema =new mongoose.Schema({
    title:{
        type:String,
        minlength:6,
        maxlength:12
    },
    content:{
        type:String,
        minlength:10,
        maxlength:50
    },
    top:{
        type:Boolean
    }
})
const contentModel = new mongoose.model("content",contentSchema); 
//  contentSchema模式生成contentModel 把contentModel模型 导出去 


const userSchema = new mongoose.Schema({
    username:{
        type:String,
        minlength:5,
        maxlength:20
    },
    password:{
        type:Number,
        minlength:6,
        maxlength:18
    },
    
    emal: {
        type: String,
        validate: {
          validator: function(v) {
            return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(v);
          },
          message: '{VALUE} is not a valid phone number!'
        },
        required: [true, 'emal格式不对']
      }
    
})
const userModel = new mongoose.model("user",userSchema); 



//模型导出 12 30 行的名字
module.exports={tagModel,contentModel,userModel};